package com.derbysoft.lowcostadapter.dswitch2.handler;

import com.derbysoft.lowcostadapter.commons.exception.SystemException;
import com.derbysoft.lowcostadapter.commons.model.SystemVariable;
import com.derbysoft.lowcostadapter.commons.redis.service.SystemVariableCacheService;
import com.derbysoft.lowcostadapter.commons.repository.SystemVariableRepository;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by: jason
 * Date: 2012-09-25
 */
public abstract class AbstractDSwitch2Handler {

    @Autowired
    private SystemVariableCacheService systemVariableCacheService;

    @Autowired
    private SystemVariableRepository systemVariableRepository;

    protected SystemVariable loadSystemVariable(String name) {
        SystemVariable systemVariable = systemVariableCacheService.loadByName(name);
        if (systemVariable == null) {
            systemVariable = systemVariableRepository.findByName(name);
        }
        if (systemVariable == null) {
            throw new SystemException(String.format("system config not found:[%s] !!", name));
        }
        return systemVariable;
    }
}
